function [x,w] = gl(n)
% Returns two (n x 1)-matrices containing the knots and weights, 
% respectively, of the Gauss-Legendre quadrature with n knots. The number 
% of knots is limited to 20. 

switch n    
    case 1
        x = 0.000000;
        w = 2.000000;
    case 2
        x = [-0.577350; 0.577350];
        w = [1.000000; 1.000000];
    case 3
        x = [-0.774597; 0.000000; 0.774597];
        w = [0.555556; 0.888889; 0.555556];
    case 4
        x = [-0.861136; -0.339981; 0.339981; 0.861136];
        w = [0.347855; 0.652145; 0.652145; 0.347855];
    case 5
        x = [-0.906180; -0.538469; 0.000000; 0.538469; 0.906180];
        w = [0.236927; 0.478629; 0.568889; 0.478629; 0.236927];
    case 6
        x = [-0.932470; -0.661209; -0.238619; 0.238619; 0.661209; 0.932470];
        w = [0.171324; 0.360762; 0.467914; 0.467914; 0.360762; 0.171324];
    case 7
        x = [-0.949108; -0.741531; -0.405845; -0.000000; 0.405845; 0.741531; 0.949108];
        w = [0.129485; 0.279705; 0.381830; 0.417959; 0.381830; 0.279705; 0.129485];
    case 8
        x = [-0.960290; -0.796666; -0.525532; -0.183435; 0.183435; 0.525532; 0.796666; 0.960290];
        w = [0.101229; 0.222381; 0.313707; 0.362684; 0.362684; 0.313707; 0.222381; 0.101229];
    case 9
        x = [-0.968160; -0.836031; -0.613371; -0.324253; -0.000000; 0.324253; 0.613371; 0.836031; 0.968160];
        w = [0.081274; 0.180648; 0.260611; 0.312347; 0.330239; 0.312347; 0.260611; 0.180648; 0.081274];
    case 10
        x = [-0.973907; -0.865063; -0.679410; -0.433395; -0.148874; 0.148874; 0.433395; 0.679410; 0.865063; 0.973907];
        w = [0.066671; 0.149451; 0.219086; 0.269267; 0.295524; 0.295524; 0.269267; 0.219086; 0.149451; 0.066671];
    case 11
        x = [-0.978229; -0.887063; -0.730152; -0.519096; -0.269543; -0.000000; 0.269543; 0.519096; 0.730152; 0.887063; 0.978229];
        w = [0.055669; 0.125580; 0.186290; 0.233194; 0.262805; 0.272925; 0.262805; 0.233194; 0.186290; 0.125580; 0.055669];
    case 12
        x = [-0.981561; -0.904117; -0.769903; -0.587318; -0.367831; -0.125233; 0.125233; 0.367831; 0.587318; 0.769903; 0.904117; 0.981561];
        w = [0.047175; 0.106939; 0.160078; 0.203167; 0.233493; 0.249147; 0.249147; 0.233493; 0.203167; 0.160078; 0.106939; 0.047175];
    case 13
        x = [-0.984183; -0.917598; -0.801578; -0.642349; -0.448493; -0.230458; 0.000000; 0.230458; 0.448493; 0.642349; 0.801578; 0.917598; 0.984183];
        w = [0.040484; 0.092121; 0.138874; 0.178146; 0.207816; 0.226283; 0.232552; 0.226283; 0.207816; 0.178146; 0.138874; 0.092121; 0.040484];
    case 14
        x = [-0.986284; -0.928435; -0.827201; -0.687293; -0.515249; -0.319112; -0.108055; 0.108055; 0.319112; 0.515249; 0.687293; 0.827201; 0.928435; 0.986284];
        w = [0.035119; 0.080158; 0.121519; 0.157203; 0.185538; 0.205198; 0.215264; 0.215264; 0.205198; 0.185538; 0.157203; 0.121519; 0.080158; 0.035119];
    case 15
        x = [-0.987993; -0.937273; -0.848207; -0.724418; -0.570972; -0.394151; -0.201194; 0.000000; 0.201194; 0.394151; 0.570972; 0.724418; 0.848207; 0.937273; 0.987993];
        w = [0.030753; 0.070366; 0.107159; 0.139571; 0.166269; 0.186161; 0.198431; 0.202578; 0.198431; 0.186161; 0.166269; 0.139571; 0.107159; 0.070366; 0.030753];
    case 16
        x = [-0.989401; -0.944575; -0.865631; -0.755404; -0.617876; -0.458017; -0.281604; -0.095013; 0.095013; 0.281604; 0.458017; 0.617876; 0.755404; 0.865631; 0.944575; 0.989401];
        w = [0.027152; 0.062254; 0.095159; 0.124629; 0.149596; 0.169157; 0.182603; 0.189451; 0.189451; 0.182603; 0.169157; 0.149596; 0.124629; 0.095159; 0.062254; 0.027152];
    case 17
        x = [-0.990575; -0.950676; -0.880239; -0.781514; -0.657671; -0.512691; -0.351232; -0.178484; -0.000000; 0.178484; 0.351232; 0.512691; 0.657671; 0.781514; 0.880239; 0.950676; 0.990575];
        w = [0.024148; 0.055460; 0.085036; 0.111884; 0.135136; 0.154046; 0.168004; 0.176563; 0.179446; 0.176563; 0.168004; 0.154046; 0.135136; 0.111884; 0.085036; 0.055460; 0.024148];
    case 18
        x = [-0.991565; -0.955824; -0.892602; -0.803705; -0.691687; -0.559771; -0.411751; -0.251886; -0.084775; 0.084775; 0.251886; 0.411751; 0.559771; 0.691687; 0.803705; 0.892602; 0.955824; 0.991565];
        w = [0.021616; 0.049715; 0.076426; 0.100942; 0.122555; 0.140643; 0.154685; 0.164276; 0.169142; 0.169142; 0.164276; 0.154685; 0.140643; 0.122555; 0.100942; 0.076426; 0.049715; 0.021616];
    case 19
        x = [-0.992407; -0.960208; -0.903156; -0.822715; -0.720966; -0.600545; -0.464571; -0.316564; -0.160359; -0.000000; 0.160359; 0.316564; 0.464571; 0.600545; 0.720966; 0.822715; 0.903156; 0.960208; 0.992407];
        w = [0.019462; 0.044814; 0.069045; 0.091490; 0.111567; 0.128754; 0.142607; 0.152766; 0.158969; 0.161054; 0.158969; 0.152766; 0.142607; 0.128754; 0.111567; 0.091490; 0.069045; 0.044814; 0.019462];
    case 20
        x = [-0.993129; -0.963972; -0.912234; -0.839117; -0.746332; -0.636054; -0.510867; -0.373706; -0.227786; -0.076527; 0.076527; 0.227786; 0.373706; 0.510867; 0.636054; 0.746332; 0.839117; 0.912234; 0.963972; 0.993129];
        w = [0.017614; 0.040601; 0.062672; 0.083277; 0.101930; 0.118195; 0.131689; 0.142096; 0.149173; 0.152753; 0.152753; 0.149173; 0.142096; 0.131689; 0.118195; 0.101930; 0.083277; 0.062672; 0.040601; 0.017614];
    otherwise 
        error('Not available.');
end

